<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增素材')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-material-add">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">分组id：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="groupId" name="groupId"  type="hidden"/>
                        <input class="form-control" type="text" onclick="selectgroupIdTree()" id="groupIdName" readonly="true">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">站点id：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="siteId" name="siteId"  type="hidden"/>
                        <input class="form-control" type="text" onclick="selectSiteTree()" id="siteName" readonly="true">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">素材名称：</label>
                <div class="col-sm-8">
                    <input name="materialName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">素材类型 字典 1图片2视频：</label>
                <div class="col-sm-8">
                    <select name="materialType" class="form-control m-b" th:with="type=${@dict.getType('material_type')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">素材描述：</label>
                <div class="col-sm-8">
                    <input name="description" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">素材大小：</label>
                <div class="col-sm-8">
                    <input name="materialSize" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">保存路径：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="savePath">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="savePath" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">分辨率 宽：</label>
                <div class="col-sm-8">
                    <input name="width" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">分辨率 高：</label>
                <div class="col-sm-8">
                    <input name="height" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="sort" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "cms/material"
        $("#form-material-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-material-add').serialize());
            }
        }

        $(".file-upload").fileinput({
            uploadUrl: '/common/upload',
            maxFileCount: 1,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })

        /*站点选择*/
        function selectSiteTree() {
            var options = {
                title: '站点选择',
                width: "380",
                url: ctx + "system/site" + "/selectWjSiteTree/",
                callBack: doSubmitSiteTree
            };
            $.modal.openOptions(options);
        }

        function doSubmitSiteTree(index, layero){
            var body = layer.getChildFrame('body', index);
            $("#siteId").val(body.find('#treeId').val());
            $("#siteName").val(body.find('#treeName').val());
            layer.close(index);
        }

            
        /*分组id选择*/
        function selectgroupIdTree() {
            var options = {
                title: '分组id选择',
                width: "380",
                url: ctx + "cms/materialGroup/selectMaterialGroupTree/",
                callBack: doSubmitgroupIdTree
            };
            $.modal.openOptions(options);
        }

        function doSubmitgroupIdTree(index, layero){
            var body = layer.getChildFrame('body', index);
            $("#groupId").val(body.find('#treeId').val());
            $("#groupIdName").val(body.find('#treeName').val());
            layer.close(index);
        }



    </script>
</body>
</html>